import 'dart:convert';
import 'package:meta/meta.dart';

class Good {
  final int product_id;
  final String product_name;
  final String product_icon;
  final String product_img;
  final String product_sbu;
  final int product_price;
  final int product_type;
  final String type_name;
  final int sale_count;

  Good(
      {
        @required this.product_id,
        @required this.product_name,
        @required this.product_icon,
        @required this.product_img,
        @required this.product_sbu,
        @required this.product_price,
        @required this.product_type,
        @required this.type_name,
        @required this.sale_count
      });

  static List<Good> fromJson(String json){
    List<Good> _goods = [];
    JsonDecoder decoder = new JsonDecoder();
    var mapData = decoder.convert(json)['data']['goodsList'];
    mapData.forEach((obj){
      Good good = new Good(
          product_id: obj['product_id'],
          product_name: obj['product_name'],
          product_icon: obj['product_icon'],
          product_img:  obj['product_img'],
          product_sbu: obj['product_sbu'],
          product_price: obj['product_price'],
          product_type: obj['product_type'],
          type_name: obj['type_name'],
          sale_count: obj['sale_count']
      );
      _goods.add(good);
    });
    return _goods;
  }
}